home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / lanutsrc.zip / USERLIST.C < prev    next >
Text File  |  1991-03-13  |  6KB  |  221 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <dos.h>
  5. #include <direct.h>
  6. #include <conio.h>
  7.  
  8. #include "lantasti.h"
  9.  
  10. #define DOS 0x21
  11. #define NETBIOS 0x5C
  12. #define DELIM "+, "
  13.  
  14. /* structure to allow easy access to both segment and offset portions of
  15.    far pointers */
  16. #define LIST_SIZE 50
  17. #define NAME_SIZE 20
  18. typedef struct LIST {
  19.     int  num_servers;
  20.     char server[LIST_SIZE][NAME_SIZE];
  21.        } LIST;  
  22.        
  23. /* definitions to save typing time */
  24. #define C_SERVER list->server[i]
  25.  
  26. /***********************************************************************
  27.  Delete leading and trailing blanks.
  28. ***********************************************************************/
  29. void dltb(string)
  30.   char *string;
  31. {
  32.   int i;
  33.  
  34.   i  = strspn(string, " ");
  35.  
  36.   if (i) strcpy(string,string + i);
  37.  
  38.   i = strlen(string) - 1;
  39.   while (i && (string[i] == ' ')) {
  40.     string[i--] = '\0';
  41.   }
  42. }
  43.  
  44. /* getstring ********************************************************************
  45.  Get a string from the console -- takes a pointer to a string buffer, the 
  46.  longest permissible length and two switches. The empty switch determines
  47.  whether or not the user is allowed to enter an empty string. If TRUE, he
  48.  can, if FALSE, he must enter something.  The shown switch determines 
  49.  whether or not input is echoed to the screen, TRUE if echoed, FALSE if
  50.  invisible
  51. *****************************************************************************/
  52. void getstring(prompt,buffer,length,empty,shown) 
  53.   char *prompt,*buffer;
  54.   int length,empty,shown;
  55. {
  56.   fprintf(stdout,"%s",prompt);
  57.   fgets(buffer,length,stdin);
  58.   if (buffer[strlen(buffer) - 1] == '\n') buffer[strlen(buffer) - 1] = 0;
  59.   while (!(strlen(buffer) || empty)) {
  60.     fprintf(stdout,"%s",prompt);
  61.     fgets(buffer,length,stdin);
  62.     if (buffer[strlen(buffer) - 1] == '\n') buffer[strlen(buffer) - 1] = 0;
  63.   }
  64. }
  65.  
  66. /* error ********************************************************************
  67.  
  68. *****************************************************************************/
  69. void error(code,message)
  70.   int code;
  71.   char *message;
  72. {
  73.   char *ptr;
  74.   
  75.   if (code) {
  76.     ptr = get_error_text(code);
  77.     puts(ptr);
  78.   }
  79.   else puts(message);
  80. }
  81.  
  82. /* get_active_servers ********************************************************************
  83.  
  84. *****************************************************************************/
  85. void get_active_servers(list)
  86.   LIST *list;
  87. {
  88.   char buffer[17];
  89.   int index,result;
  90.   
  91.   index = 0;
  92.   result = get_active_server(buffer,index);
  93.   while (result) {
  94.     strcpy(list->server[list->num_servers++],buffer);
  95.     if (list->num_servers >= LIST_SIZE) {
  96.       puts("Warning: Too many servers.  Only the first 50 can be used.");
  97.       break;
  98.     }
  99.     result = get_active_server(buffer,++index);
  100.   }
  101. }
  102.  
  103. /* process_server_list ********************************************************************
  104.  
  105. *****************************************************************************/
  106. void process_server_list(string,list)
  107.   char *string;
  108.   LIST *list;
  109. {
  110.   char *ptr;
  111.   
  112.   ptr = strtok(string,DELIM);
  113.   
  114.   while (ptr !=NULL) {
  115.     if (!strcmp(ptr,"/HELP")) {
  116.       puts("USERLIST utility for LANtastic -- Copyright 1989 by SoftMagic, Inc.");
  117.       puts("All rights reserved.  LANtastic is a trademark of Artisoft, Inc.\n");
  118.       puts("Usage: USERLIST <server list> [/OPTIONS]");
  119.       puts("  A question mark in the list causes the program to prompt the user");
  120.       puts("  for input.  USERLIST with no arguments will list users for all");
  121.       puts("  active servers.\n");
  122.       puts("Available options are:");
  123.       puts("/HELP - display this documentation");
  124.       exit(0);
  125.       break;
  126.     }
  127.     if (*ptr == '*') {
  128.       list->num_servers = 0;
  129.       get_active_servers(list);
  130.       break;
  131.     }
  132.     else {
  133.       strcpy(list->server[list->num_servers++],ptr);
  134.     }
  135.  
  136.     if (list->num_servers >= LIST_SIZE ) {
  137.       puts("Warning: Too many servers.  Only the first 50 will be used.");
  138.       break;
  139.     }
  140.     ptr = strtok(NULL," ,");
  141.   }
  142.  
  143. /* if no servers are given, list out of everything */
  144.   if (list->num_servers == 0) get_active_servers(list);
  145. }
  146.   
  147. /* scan_command_line ********************************************************************
  148.  
  149. *****************************************************************************/
  150. scan_command_line(argc,argv,list)
  151.   int argc;
  152.   char *argv[];
  153.   LIST *list;
  154. {
  155.   int i;
  156.   char buffer[1];
  157.  
  158.   buffer[0] = 0;
  159.   list->num_servers = 0;
  160.   if (argc < 2) process_server_list(buffer,list);
  161.   
  162.   for (i = 1;i < argc; i++) {
  163.     strupr(argv[i]);
  164.     process_server_list(argv[i],list);
  165.   }
  166. }
  167.  
  168. /* do_userlist ********************************************************************
  169.  
  170. *****************************************************************************/
  171. int do_userlist(list)
  172.   LIST *list;
  173. {
  174.   int i,j,num_users;
  175.   char userlist_buffer[128];
  176.   ACTIVE_USER user;
  177.  
  178.   for (i = 0; i < list->num_servers; i++) {
  179. /* see if we've got any "?"s in the list */
  180.     if (C_SERVER[0] == '?') {
  181.       getstring("Server: ",userlist_buffer,128,FALSE,TRUE);
  182.       list->num_servers = i;
  183.       process_server_list(userlist_buffer,list);
  184.     }
  185.     dltb(C_SERVER);
  186.     printf("\nUsers on server %s:\n",C_SERVER);
  187.     j = num_users = 0;
  188.     sprintf(userlist_buffer,"\\\\%s",C_SERVER);
  189.     while (!get_user_info(userlist_buffer,j++,&user)) {
  190.       num_users++;
  191.       dltb(user.name); dltb(user.machine);
  192.       printf("  %s on machine %s\n",user.name,user.machine);
  193.     }
  194.     printf("(%d users)\n",num_users);
  195.   }
  196. }
  197.  
  198. /* main ********************************************************************
  199.  
  200. *****************************************************************************/
  201. int main(argc,argv)
  202.   int argc;
  203.   char *argv[];
  204. {
  205.   LIST  list;        /*server, user and password lists*/ 
  206.   int serverno;        /*index into serverlist*/
  207.  
  208. #ifdef SHAREWARE
  209.   puts("USERLIST utility for LANtastic -- Copyright 1989 by SoftMagic, Inc.");
  210.   puts("All rights reserved.  Thanks for trying this unregistered Shareware edition!\n");
  211. #endif  
  212.   
  213.   scan_command_line(argc,argv,&list);  
  214.   
  215.   if (list.num_servers > 0) do_userlist(&list);
  216.   else error(FALSE,"You are not logged in to any servers.");
  217.   
  218.   return(0);
  219.  
  220. }
  221.